﻿Imports System.Windows.Forms

Public Class ManageImportPoliceHealthData
    Protected _year As String
    Protected _Data As ArrayList
    Protected _DataCurrent As Integer

    Public Property year() As String
        Get
            Return _year
        End Get
        Set(ByVal value As String)
            _year = value
        End Set
    End Property

    Public Function getImportDataYear() As System.Data.DataSet
        'Dim decryptText As New DateUtilities.Encrypt_Data()
        'Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
        '    decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
        '    "PoliceHealthConnectionString").ToString(), True))

        'Dim objConn As New MySql.Data.MySqlClient.MySqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings("PoliceHealthConnectionString").ToString())

        'Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        'objCmd.Connection = objConn
        'objCmd.CommandType = CommandType.StoredProcedure
        'objCmd.CommandText = "proc_SELECT_WordReportStationYear"

        'Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        'objDa.Fill(objDs, "Year")
        objDs.Tables.Add("Year")
        objDs.Tables("Year").Columns.Add("year", GetType(String))

        For i As Short = 0 To 1
            Dim objDR As DataRow = objDs.Tables("Year").NewRow()
            objDR("year") = (Date.Now.Year + 543) - i
            objDs.Tables("Year").Rows.Add(objDR)
        Next

        Return objDs
    End Function

    Public Sub GenerateOrganization(ByVal trvInput As TreeNode, ByVal ParentOrganizationID As Integer, Optional ByVal level As Integer = 0)
        Dim OrganizationBuffer As New PoliceHealthClass.Organization
        OrganizationBuffer.LoadOrganizationChild(ParentOrganizationID)

        While OrganizationBuffer.NextRecord

            Dim trvBuffer As New TreeNode(OrganizationBuffer.organization_name_tha)
            trvBuffer.Tag = OrganizationBuffer.organization_id
            trvInput.Nodes.Add(trvBuffer)
            GenerateOrganization(trvBuffer, OrganizationBuffer.organization_id, level + 1)
        End While
    End Sub

    Protected Function getsImportDataYear() As ArrayList
        Dim outResult As New ArrayList()
        Dim decryptText As New DateUtilities.Encrypt_Data()
        Dim objConn As New MySql.Data.MySqlClient.MySqlConnection( _
            decryptText.getDecrypt(System.Configuration.ConfigurationManager.ConnectionStrings( _
            "PoliceHealthConnectionString").ToString(), True))
        Dim objCmd As New MySql.Data.MySqlClient.MySqlCommand()
        objCmd.Connection = objConn
        objCmd.CommandType = CommandType.StoredProcedure
        objCmd.CommandText = "proc_SELECT_WordReportStationYear"

        Dim objDa As New MySql.Data.MySqlClient.MySqlDataAdapter(objCmd)
        Dim objDs As New System.Data.DataSet()
        objDa.Fill(objDs, "Year")

        For Each objDr As System.Data.DataRow In objDs.Tables("Year").Rows
            Dim obj As ManageBMIResultHistoryControl = New ManageBMIResultHistoryControl
            obj.year = objDr.Item("year")
            outResult.Add(obj)
        Next

        Return outResult
    End Function

    Public Sub LoadImportDataYear()
        _Data = New ArrayList
        _DataCurrent = 0
        _Data = getsImportDataYear()
    End Sub

    Public Function NextRecord() As Boolean
        If ((Not _Data Is Nothing) AndAlso (((Not _Data Is Nothing) AndAlso _
            (_DataCurrent < _Data.Count And _Data.Count > 0)))) Then
            _year = _Data(_DataCurrent).year
            _DataCurrent += 1
            Return True
        End If
        Return False
    End Function
End Class
